<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/cts/css/style.css" type="text/css"/>
    <!-- 
	<script type="text/javascript" src="${pageContext.request.contextPath}/cts/js/jquery.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/cts/js/common.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/cts/js/popdiv.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/cts/js/jquery.bgiframe.js"></script>
     -->
  
     <script type="text/javascript">
           var type = '<s:property value="#request.type"/>'; // 成员类型
           
	       function addEmployee(id){
	          var url = "cts/findSingleEmployee.action?type=<s:property value="#request.type"/>&id="+id;
		      openPopDiv( 'addEmployee' , url ,  200);
		      
		      var type = '<s:property value="#request.type"/>' ;
		      var title = ""
		      if(type == 1){
		         title = (typeof(id)=='undefined' || id=='') ? "添加访客" : "修改访客";
		      }else{
		         title = (typeof(id)=='undefined' || id=='') ? "添加员工" : "修改员工";
		         $("#addEmployee").find("div[class='popdiv_content']").css({"height":"300px"});
		      }
		      
		      $("#addEmployee").find("div[class='popdiv_handle']").text(title);
		     
	       }
           
           function invitedEmployee(id){
              var showMsg = "邀请员工使用本系统，请输入该员工的常用邮箱 ，系统会发送邮件给对方确认。";
              if(type == '1'){
                 showMsg = "如果邀请访客使用本系统，请输入该访客的常用邮箱 ，系统会发送邮件给对方确认。";
              }
              alert(showMsg);
              addEmployee(id)
           }
           
           function delEmployee(id){
              if(!confirm("您确要进行此操作")){
		        return;
		      }
		      
		      var type = '<s:property value="#request.type"/>' ;
              var url = "cts/delEmployee?id="+id;
              $.post(url , "" , function(data){
                 if(data == 1){
                   alert("操作成功");
                   window.location.reload();
                 }else if(data == -1){
                   if(type == 1){
                     alert("此访客有相关的订单，不能删除");
                   }else{
                     alert("此员工有相关的订单，不能删除");
                   }
                 }else{
                   alert("操作失败");
                 }
              });
           }
           
           function cancalInvited(id){
             if(!confirm("您确定要取消邀请")) return;
             
             var url = "cts/cancelInvited?id="+id;
             $.post(url , "" , function(data){
                 if(data == 1){
                    alert("操作成功");
                    window.location.reload();
                 }else{
                    alert("操作失败");
                 }
             });
           }
           
           function changeUrl(type){
              window.location.href = "${pageContext.request.contextPath}/cts/findEmployee?type="+type;
           }
           
		</script>
		
		<style type="text/css">
		   #datacon table tr td{
		    height:30px;
		  }
		  
		  .selectBtn{
		     border:none;
		     padding:5px 10px 5px 10px;
		     background-color:gray;
		     float:left;
		     color:#ffffff;
		     font-weight: bold;
		  }
		  
		  .noselectBtn{
		     border:none;
		     padding:5px 10px 5px 10px;
		     background-color:#ececec;
		     float:left;
		  }
		  #tddotted{
		    border-bottom: 1px dotted gray; 
		  }
		</style>
  </head>
  
  <body>
  
  <form id="allFromPage" method="post" action="">
     <div align="center">
       <div id="datacon" style="width:773px;">
	     <table style="font-size:12px;width:95%;margin-top:20px;margin-bottom: 20px;text-align:center;" border="0" cellpadding="0" cellspacing="0">
	        <tr style="displey:none;">
	             <td style="border:none;" colspan="2">&nbsp;</td>
	             <td colspan="<s:property value="#request.type==0 ? 4 : 3"/>" align="right" style="border:none;text-align: right;">
	                <a href="javascript:addEmployee('')">
	                   <div class="btn_ok">添加</div>
	                </a>
	             </td>
	        </tr>
	        <tr>
	             <td colspan="<s:property value="#request.type==0 ? 6 : 5"/>" align="right">
	                    名称：<input id="keyword" name="keyword" value="<s:property value="keyword"/>" style="width:100px;"/>
	                  &nbsp;&nbsp;    
	                     状态：<select id="searchstatus" name="searchstatus">
	                   <option id="" value="">全部</option>
		               <option id="1" value="1">正常</option>
		               <option id="2" value="2">禁用</option>
	                </select>
	                &nbsp;&nbsp;
	                <input type="button" value="查询" onclick="getParam(1)"/>
	             </td>
	          </tr>
	          
	        <tr class="trChNodeBg">
	           <td width="10%" class="td1 td0">昵称</td>
	           <s:if test="#request.type==0">
	             <td width="25%" class="td2 td0">权限</td>
	           </s:if>
	           <s:else>
	             <td width="25%" class="td2 td0">全称</td>
	           </s:else>
	           <td width="15%" class="td2 td0">cts用户</td>
	           <td width="15%" class="td2 td0">禁用</td>
	           <td width="15%" class="td2 td0">操作</td>
	        </tr>
	         <s:iterator value="#request.employeelist" status="sta">
	           <tr <s:if test="#sta.index%2!=0 ">class="clBg"</s:if><s:else>class="clBg2"</s:else>>
		           <td class="td1">
		              <s:if test="nickname==null || nickname==''">
		                 <s:property value="user.userName"/>
		              </s:if>
		              <s:else>
		                 <s:property value="nickname"/>&nbsp;
		              </s:else>
		           </td>
		           <s:if test="#request.type == 0">
			           <td  class="td2" style="font-size:10px;">
			              <s:if test="auth1 ==1">创建订单,&nbsp;</s:if>
			              <s:if test="auth2 ==1">创建订单奖励,&nbsp;</s:if>
			              <s:if test="auth3 ==1">创建委托项目,&nbsp;</s:if>
			              <s:if test="auth4 ==1">创建标签,&nbsp;</s:if>
			              <s:if test="auth5 ==1">创建访客,&nbsp;</s:if>
			              <s:if test="auth6 ==1">创建文档模版,&nbsp;</s:if>
			              <s:if test="auth7 ==1">创建财务收入,&nbsp;</s:if>
			              <s:if test="auth8 ==1">创建财务支出,&nbsp;</s:if>
			              <s:if test="auth9 ==1">创建财务奖励</s:if>
			              <s:if test="auth10 ==1">创建费用</s:if>
			              &nbsp;
			           </td>
		           </s:if>
		           <s:else>
		             <td  class="td2">
		                <s:property value="fullname"/>&nbsp;
		             </td>
		           </s:else>
		           <td class="td2">
		              <s:if test="invite == 1">
		                   <span  title="<s:property value="user.userName"/>">邀请中..</span>.
		              </s:if>
		              <s:else>
			              <s:property value="user.userName"/>&nbsp;
		              </s:else>
		           </td>
		           <td class="td2">
		               <s:if test="status == 1">否</s:if>
		               <s:else>是</s:else>
		                 &nbsp;
		           </td>
		           <td  class="td2">
		             <a href="javascript:addEmployee('<s:property value="id"/>')">修改</a> | 
		             <s:if test="user==null || user.id == 0">
			             <a href="javascript:invitedEmployee('<s:property value="id"/>')">邀请</a> | 
		             </s:if>
		             <s:else>
		                 <a href="javascript:cancalInvited('<s:property value="id"/>')">取消邀请</a> | 
		             </s:else>
		             <a href="javascript:stopToUsing('<s:property value="id"/>' , 'em0')">禁用</a>
		           </td>
	           </tr>
	         </s:iterator>
	     </table>
	     
			<jsp:include page="pageForm.jsp"></jsp:include>
			<input type="hidden" id="urlforward"  value="" />
			<div id="pagination" valign="middle" class="pagination" ></div>
	      
	     </div>
     </div>
     
     <div id="addEmployee" name="n_addEmployee" class="popdiv_inner" style="width:300px;">
			<div class="popdiv_inner_outter"></div>
			<div class="popdiv_close"></div>
			<div class="popdiv_handle" title="鼠标左键按住可拖动">公司员工</div>
			<div class="popdiv_content" style="height:170px;text-align: center;">top:200</div>
	 </div>
  </body>
</form>  
</html>


<script type="text/javascript">
	function getParam(istype) {
	    $("#pageSize").val( $("#pageSize").val());
	    var pageNumberS = $("#pageNumber").val();
	    if(parseInt(pageNumberS) <= 0 || istype == 1){
	    	pageNumberS = '1';
	    }
	    $("#pageNumber").val(pageNumberS);
	    submitForm('<s:property value="#request.type"/>');
	}		    
	
	paginationCommon(1);
</script>